<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Calculate the metaphone key of a string</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.md5.html">« md5</a></li>
      <li style="float: right;"><a href="function.money-format.html">money_format »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.strings.html">字符串 函数</a></li>
    <li>Calculate the metaphone key of a string</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.metaphone" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">metaphone</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">metaphone</span> &mdash; <span class="dc-title">Calculate the metaphone key of a string</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.metaphone-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>metaphone</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$max_phonemes</code><span class="initializer"> = 0</span></span>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   Calculates the metaphone key of <code class="parameter">string</code>.
  </p>
  <p class="para">
   Similar to <span class="function"><a href="function.soundex.html" class="function">soundex()</a></span> metaphone creates the same key for
   similar sounding words. It&#039;s more accurate than
   <span class="function"><a href="function.soundex.html" class="function">soundex()</a></span> as it knows the basic rules of English
   pronunciation.  The metaphone generated keys are of variable length.
  </p>
  <p class="para">
   Metaphone was developed by Lawrence Philips
   &lt;lphilips at verity dot com&gt;. It is described in [&quot;Practical
   Algorithms for Programmers&quot;, Binstock &amp; Rex, Addison Wesley,
   1995].
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.metaphone-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">string</code></dt>

     <dd>

      <p class="para">
       The input string.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">max_phonemes</code></dt>

     <dd>

      <p class="para">
       This parameter restricts the returned metaphone key to 
       <code class="parameter">max_phonemes</code> <em class="emphasis">characters</em> in length.
       However, the resulting phonemes are always transcribed completely, so the
       resulting string length may be slightly longer than <code class="parameter">max_phonemes</code>.
       The default value of <code class="literal">0</code> means no restriction.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.metaphone-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the metaphone key as a string.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.metaphone-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       The function returned <strong><code>false</code></strong> on failure.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.metaphone-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="metaphone.example.basic">
    <p><strong>示例 #1 <span class="function"><strong>metaphone()</strong></span> basic example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">metaphone</span><span style="color: #007700">(</span><span style="color: #DD0000">'programming'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">metaphone</span><span style="color: #007700">(</span><span style="color: #DD0000">'programmer'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
string(7) &quot;PRKRMNK&quot;
string(6) &quot;PRKRMR&quot;
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="metaphone.example.phonemes">
    <p><strong>示例 #2 Using the <code class="parameter">max_phonemes</code> parameter</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">metaphone</span><span style="color: #007700">(</span><span style="color: #DD0000">'programming'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">metaphone</span><span style="color: #007700">(</span><span style="color: #DD0000">'programmer'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
string(5) &quot;PRKRM&quot;
string(5) &quot;PRKRM&quot;
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="metaphone.example.phonemes-overlong">
    <p><strong>示例 #3 Using the <code class="parameter">max_phonemes</code> parameter</strong></p>
    <div class="example-contents"><p>
     In this example, <span class="function"><strong>metaphone()</strong></span> is advised to produce a string
     of five characters, but that would require to split the final phoneme
     (<code class="literal">&#039;x&#039;</code> is supposed to be transcribed to <code class="literal">&#039;KS&#039;</code>),
     so the function returns a string with six characters.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">metaphone</span><span style="color: #007700">(</span><span style="color: #DD0000">'Asterix'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
string(6) &quot;ASTRKS&quot;
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div></div></div></body></html>